// 四、函数

function add1(arg1: number, arg2: number): number {
  return arg1 + arg2
}
const add2 = (arg1: number, arg2: number) => arg1 + arg2

let add3: (x: number, y: number) => number
add3 = (arg1: number, arg2: number): number => arg1 + arg2
add3 = (arg1: number, arg2: number) => arg1 + arg2

// 接口函数类型
interface Add {
  (x: number, y: number): number
}
let addFunc: Add
addFunc = (arg1: number, arg2: number): number => arg1 + arg2

// 可选参数 放在最后
let addFunc1
addFunc1 = (arg1, arg2, arg3) => arg1 + arg2 + (arg3 ? arg3 : 0)
interface AddFunction {
  (arg1: number, arg2: number, arg3?: number): number
}
let addFunction: AddFunction
addFunction = (x: number, y: number) => x + y

// 默认参数
let add4 = (x: number, y: number = 3) => x + y
// console.log(add4(1));

// 参数列表
const handleData = (arg1:number,...args:number[])=>{
  // ...
}

// 函数重载 只能通过function定义
function handle1(x:string):string[]
function handle1(x:number):number[]
function handle1(x:any):any{
  if(typeof x ==='string'){
    return x.split('')
  }else{
    return x.toString().split('').map(item=>Number(item))
  }
}
console.log(handle1('abc'));
console.log(handle1(123));


